package com.lesso.lzh.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.lzh.sunflower.domain.repository.RelEmployeeDeviceRepository;
import com.lesso.lzh.sunflower.infra.assembler.RelEmployeeDeviceAssembler;
import com.lesso.lzh.sunflower.model.RelEmployeeDevice;
import com.lesso.lzh.sunflower.pojo.dto.RelEmployeeDeviceDTO;
import com.lesso.lzh.sunflower.pojo.dto.RelEmployeeDeviceQueryDTO;
import com.lesso.lzh.sunflower.pojo.vo.RelEmployeeDeviceVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * RelEmployeeDeviceDomainService
 *
 * @author zqz
 * @since 2025-07-05
 */
@Service
public class RelEmployeeDeviceDomainService {

    private final RelEmployeeDeviceRepository relEmployeeDeviceRepository;

    public RelEmployeeDeviceDomainService(RelEmployeeDeviceRepository relEmployeeDeviceRepository) {
        this.relEmployeeDeviceRepository = relEmployeeDeviceRepository;
    }

    public Long save(RelEmployeeDeviceDTO dto) {
        return relEmployeeDeviceRepository.save(RelEmployeeDeviceAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<RelEmployeeDeviceVO> page(RelEmployeeDeviceQueryDTO dto) {
        return relEmployeeDeviceRepository.getPageList(dto);
    }

    public Page<RelEmployeeDeviceVO> customPage(RelEmployeeDeviceQueryDTO dto) {
        return relEmployeeDeviceRepository.getCustomPageList(dto);
    }

    public void deleteById(Long id) {
        relEmployeeDeviceRepository.removeById(id);
    }

    public RelEmployeeDevice selectById(Long id) {
        return relEmployeeDeviceRepository.selectById(id);
    }

    public void update(RelEmployeeDevice relEmployeeDevice) {
        relEmployeeDeviceRepository.update(relEmployeeDevice);
    }

    public List<RelEmployeeDeviceVO> listByEmployeeId(Long employeeId) {
        // 示例：可添加权限校验逻辑（如校验当前用户是否有权查看该员工设备）
        List<RelEmployeeDevice> entities = relEmployeeDeviceRepository.listByEmployeeId(employeeId);
        return RelEmployeeDeviceAssembler.INSTANCE.entityListToVOList(entities);
    }
}